package stu.sup.controller.product;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import stu.sup.dto.ClasstableDTO;
import stu.sup.entity.ClassTable;
import stu.sup.entity.Product;
import stu.sup.entity.ProductTpicInfo;
import stu.sup.service.IClassTableService;
import stu.sup.service.IPicInfoService;
import stu.sup.service.IProductService;
import stu.sup.service.IproductClassDTOService;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

@Controller
public class ProductClassController {
    @Autowired
    private IClassTableService classTableService;
    @Autowired
    private IProductService productService;
    @Autowired
    private IPicInfoService picInfoService;
    @Autowired
    private IproductClassDTOService classDTOService;

    //查询所有类别表
    @GetMapping("productClass")
    public String classTable(Model model,HttpServletRequest request){
        String name=request.getParameter("class");
        List<ClasstableDTO> dto=classDTOService.showAll(name);
        model.addAttribute("classTable",dto);
        return "view/product-class";
    }
    //根据商品类别名查询该商品
//    @GetMapping("classtable")
//    public String  findbyclass(Model model,HttpServletRequest httpServletRequest){
//        String name=httpServletRequest.getParameter("class");
//        List<ClassTable> classTables=classTableService.find(name);
//        List<Product> products=new ArrayList<>();
//        for (ClassTable c : classTables) {
//            products.add( productService.selectbyId(c.getProductId()));
//        }
//        model.addAttribute("classTable" ,classTables);
//        return "view/product-class";
//    }
}
